<template>
  <div>
    <div id="community">
      <van-list
        v-model:loading="state.loading"
        :finished="state.finished"
        finished-text="没有更多了"
        @load="onLoad"
        class="ul"
      >
        <div
          class="video-item"
          v-for="item in state.vidolist"
          v-bind:key="item.comment_id"
        >
          <router-link :to="{name:'vido',params:{id:item.goods_id}}">
            <van-icon name="play-circle" class="iconfont" />
            <van-image width="100%" height="63.46vw" :src="item.goods_img" />
            <div class="video-text">
              <p class="goods-name">{{ item.goods_name }}</p>
              <div class="video-info">
                <div class="video-name">
                  <van-image
                    class="user_picture"
                    round
                    width="22px"
                    height="22px"
                    :src="item.logo_thumb"
                  />
                  <span>{{ item.shop_name }}</span>
                </div>
                <div class="video-span">
                  <van-icon class="eye" name="eye-o" />
                  <span class="size">{{ item.look_num }}</span>
                </div>
              </div>
            </div>
          </router-link>
        </div>
      </van-list>
    </div>
  </div>
</template>
<script>
import { reactive } from "vue";
import store from "../../store/index.js";

export default {
  setup() {
    const state = reactive({
      vidolist: [],
      loading: false,
      finished: false,
      size: 10,
      page: 1,
    });

    const onLoad = () => {
      state.loading = true;
      store
        .dispatch({
          type: "getvideo",
          size: state.size,
          page: state.page,
        })
        .then((data) => {
          state.vidolist = [...state.vidolist, ...data];
          // console.log(state.vidolist);
          state.page = state.page + 1;
          state.loading = false;
          if (state.vidolist.length >= 14) {
            state.finished = true;
            // console.log(state.finished);
          }
        });
    };

    return {
      state,
      onLoad,
    };
  },
};
</script>
<style lang="less" scoped>
* {
  margin: 0;
  padding: 0;
}
#community {
  padding: 10px 7px 0 7px;
  display: flex;
  justify-content: space-between;
  margin-bottom: 51px;
  .ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    margin-bottom: 10px;
    .video-item {
      position: relative;
      width: 168.656px;
      height: 331.45px;
      border-radius: 1rem;
      background-color: #fff;
      overflow: hidden;
      margin-top: 10px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .iconfont {
        color: #fff;
        font-size: 20px;
        position: absolute;
        top: 20.8px;
        left: 12.8px;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1;
        border-radius: 50%;
        border: none;
      }
      .video-img {
        width: 169.34px;
        height: 170.42px;
      }
      .goods-name {
        font-size: 15px;
        font-weight: 500;
        color: #333;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
      }
      .video-info {
        display: flex;
        justify-content: space-between;
        margin-top: 10px;
        .video-name {
          display: flex;
          .user_picture {
            margin-right: 5px;
          }
          span {
            // height: 22px;
            width: 75px;
            display: inline-block;
            font-size: 12px;
            color: #333;
            line-height: 22px;
          }
        }
        .video-span {
          font-weight: 400;
          font-size: 12px;
          color: #333;
          line-height: 22px;
          // margin-right: 10px;
          .eye {
            font-size: 16px;
          }
        }
      }
    }
  }
  .video-text {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 77px;
    padding: 10px 10px 16px 10px;
  }
}
</style>